home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / networking / terms / tipx / tipout.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-11  |  3.9 KB  |  176 lines

  1. /*
  2.  * Copyright (c) 1983 The Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms are permitted
  6.  * provided that the above copyright notice and this paragraph are
  7.  * duplicated in all such forms and that any documentation,
  8.  * advertising materials, and other materials related to such
  9.  * distribution and use acknowledge that the software was developed
  10.  * by the University of California, Berkeley.  The name of the
  11.  * University may not be used to endorse or promote products derived
  12.  * from this software without specific prior written permission.
  13.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  14.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  15.  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  16.  */
  17. /*+:EDITS:*/
  18. /*:05-08-1990-15:29-wht@n4hgf-rawthru */
  19. /*:05-08-1990-15:28-wht@n4hgf-mv tipout.c tipout-orig.c */
  20.  
  21. #ifndef lint
  22. static char sccsid[] = "@(#)tipout.c    5.2 (Berkeley) 9/2/88";
  23. #endif /* not lint */
  24.  
  25. #include "tip.h"
  26. /*
  27.  * tip
  28.  *
  29.  * lower fork of tip -- handles passive side
  30.  *  reading from the remote host
  31.  */
  32.  
  33. static    jmp_buf sigbuf;
  34.  
  35. /*
  36.  * TIPOUT wait state routine --
  37.  *   sent by TIPIN when it wants to posses the remote host
  38.  */
  39. sigfunc_t
  40. intIOT()
  41. {
  42.  
  43.     write(repdes[1],&ccc,1);
  44.     read(fildes[0], &ccc,1);
  45.     longjmp(sigbuf, 1);
  46. }
  47.  
  48. /*
  49.  * Scripting command interpreter --
  50.  *  accepts script file name over the pipe and acts accordingly
  51.  */
  52. sigfunc_t
  53. intEMT()
  54. {
  55.     char c, line[256];
  56.     register char *pline = line;
  57.     char reply;
  58.  
  59.     read(fildes[0], &c, 1);
  60.     while (c != '\n') {
  61.         *pline++ = c;
  62.         read(fildes[0], &c, 1);
  63.     }
  64.     *pline = '\0';
  65.     if (boolean(value(SCRIPT)) && fscript != NULL)
  66.         fclose(fscript);
  67.     if (pline == line) {
  68.         boolean(value(SCRIPT)) = FALSE;
  69.         reply = 'y';
  70.     } else {
  71.         if ((fscript = fopen(line, "a")) == NULL)
  72.             reply = 'n';
  73.         else {
  74.             reply = 'y';
  75.             boolean(value(SCRIPT)) = TRUE;
  76.         }
  77.     }
  78.     write(repdes[1], &reply, 1);
  79.     longjmp(sigbuf, 1);
  80. }
  81.  
  82. sigfunc_t
  83. intTERM()
  84. {
  85.  
  86.     if (boolean(value(SCRIPT)) && fscript != NULL)
  87.         fclose(fscript);
  88.     finish();
  89. }
  90.  
  91. sigfunc_t
  92. intSYS()
  93. {
  94.  
  95.     boolean(value(BEAUTIFY)) = !boolean(value(BEAUTIFY));
  96.     longjmp(sigbuf, 1);
  97. }
  98.  
  99. #ifdef TIPX
  100. extern int rawthru;
  101. sigfunc_t
  102. int_tipout_rawthru_on()
  103. {
  104.     rawthru = 1;
  105. }
  106. sigfunc_t
  107. int_tipout_rawthru_off()
  108. {
  109.     rawthru = 0;
  110. }
  111. #endif /* TIPX */
  112.  
  113. /*
  114.  * ****TIPOUT   TIPOUT****
  115.  */
  116. tipout()
  117. {
  118.     char buf[BUFSIZ];
  119.     register char *cp;
  120.     register int cnt;
  121.     extern int errno;
  122.     int omask;
  123.  
  124.     signal(SIGINT, SIG_IGN);
  125.     signal(SIGQUIT, SIG_IGN);
  126.     signal(SIGEMT, intEMT);        /* attention from TIPIN */
  127.     signal(SIGTERM, intTERM);    /* time to go signal */
  128.     signal(SIGIOT, intIOT);        /* scripting going on signal */
  129.     signal(SIGHUP, intTERM);    /* for dial-ups */
  130.     signal(SIGSYS, intSYS);        /* beautify toggle */
  131. #ifdef TIPX
  132.     signal(SIGUSR1, int_tipout_rawthru_on);
  133.     signal(SIGUSR2, int_tipout_rawthru_off);
  134. #endif /* TIPX */
  135.     (void) setjmp(sigbuf);
  136.     for (omask = 0;; sigsetmask(omask)) {
  137.         cnt = read(FD, buf, BUFSIZ);
  138.         if (cnt <= 0) {
  139.             /* lost carrier */
  140.             if (cnt < 0 && errno == EIO) {
  141.                 sigblock(sigmask(SIGTERM));
  142.                 intTERM();
  143.                 /*NOTREACHED*/
  144.             }
  145.             continue;
  146.         }
  147. #ifdef TIPX
  148. #define    ALLSIGS    sigmask(SIGEMT)|sigmask(SIGTERM)|sigmask(SIGIOT)|sigmask(SIGSYS)|sigmask(SIGUSR1)|sigmask(SIGUSR2)
  149. #else /* TIPX */
  150. #define    ALLSIGS    sigmask(SIGEMT)|sigmask(SIGTERM)|sigmask(SIGIOT)|sigmask(SIGSYS)
  151. #endif /* TIPX */
  152.         omask = sigblock(ALLSIGS);
  153. #ifdef TIPX
  154.         if(!rawthru)
  155. #endif
  156.         for (cp = buf; cp < buf + cnt; cp++)
  157.             *cp &= 0177;
  158.         write(1, buf, cnt);
  159.         if (boolean(value(SCRIPT)) && fscript != NULL) {
  160.             if (!boolean(value(BEAUTIFY))) {
  161.                 fwrite(buf, 1, cnt, fscript);
  162.                 continue;
  163.             }
  164. #ifdef TIPX
  165.             if(rawthru)
  166.                 for (cp = buf; cp < buf + cnt; cp++)
  167.                     *cp &= 0177;
  168. #endif /* TIPX */
  169.             for (cp = buf; cp < buf + cnt; cp++)
  170.                 if ((*cp >= ' ' && *cp <= '~') ||
  171.                     any(*cp, value(EXCEPTIONS)))
  172.                     putc(*cp, fscript);
  173.         }
  174.     }
  175. }
  176.